package com.uzhie.jt808.util;

import io.netty.channel.ChannelHandlerContext;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * Created by TangFei on 2018/7/23.
 */
public class JT808SessionUtil {

    private static volatile JT808SessionUtil instance;
    private ConcurrentMap<String, ChannelHandlerContext> session = new ConcurrentHashMap<>();

    public static JT808SessionUtil getInstance() {
        if (instance == null) {
            synchronized (JT808SessionUtil.class) {
                if (instance == null) {
                    instance = new JT808SessionUtil();
                }
            }
        }
        return instance;
    }

    public ConcurrentMap<String, ChannelHandlerContext> getSession() {
        return session;
    }

    public void setSession(ConcurrentMap<String, ChannelHandlerContext> session) {
        this.session = session;
    }

    public void put(String simNum, ChannelHandlerContext handlerContext) {
        session.put(simNum, handlerContext);
    }

    public void remove(String simNum) {
        session.remove(simNum);
    }

    public ChannelHandlerContext get(String simNum) {
        return session.get(simNum);
    }

}
